package com.mapper;

import com.entity.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AdminMapper {
    //查询用户
        //查询全部用户
    @Select("select * from admin")
    List<Admin> findAllAdmin();
        //根据用户名模糊查询
    @Select("select * from admin where ad_name like \'%${name}%\'")
    List<Admin> findAdminByName(@Param("name")String name);
        //根据ID查询
    @Select("select * from admin where ad_id =#{id}")
    Admin findAdminById(@Param("id") int id);
        //根据邮箱模糊查询
    @Select("select * from admin where ad_email like \'%${email}%\'")
    List<Admin> findAdminByEmail(@Param("email")String email);

    @Select("select ad_name from admin where ad_name = #{name}")
    String findAdminName(@Param("name") String name);


    //查询全部用户数
    @Select("select count(*) from admin")
    int count();

    /**
     * 分页查询
     * @param rows 第rows页
     * @param offset 页条数
     * @return
     */
    @Select("select * from admin ORDER BY ad_id LIMIT #{rows}, #{offset}")
    List<Admin> findAdminPage(@Param("rows") int rows, @Param("offset") int offset);


    //增加用户
    @Insert("insert into admin (ad_name,ad_password,ad_avatar,ad_email,ad_create_time) value(#{ad_name},#{ad_password},#{ad_avatar},#{ad_email},#{ad_create_time})")
    int addAdmin(Admin admin);

    //修改用户资料
    @Update("update admin set ad_name=#{name},ad_avatar=#{avatar},ad_email=#{email} where ad_id = #{id}")
    int updateAdminById(@Param("id")int id,@Param("name") String name, @Param("avatar")String avatar, @Param("email")String email);

    //查询密码
    @Select("select ad_password from admin where ad_id = #{id}")
    String findPdById(@Param("id") int id);

    //修改用户密码
    @Update("update admin set ad_password=#{newPassword} where ad_id = #{id}")
    int updateAdminPd(@Param("newPassword") String newPassword,@Param("id") int id);


    //删除用户
    @Delete("delete from admin where ad_id =#{id}")
    int delAdminById(@Param("id")int id);


}
